package Test_0814.ioperations;

import Test_0814.book.Book;
import Test_0814.book.BookShelf;

import java.util.Scanner;

/**
 * Created with Intellij IDEA
 * Description:
 * User: 星辰
 * Dare: 2024-08-15
 * Time: 9:36
 */
public class DelOperation implements IoPeration{
    public void work(BookShelf bookshelf){
        System.out.println("删除图书");
        System.out.println("请输入你要删除的图书");
        Scanner scanner=new Scanner(System.in);
        String delName=scanner.nextLine();
        int ret=bookshelf.getUseSize();
        int pos=-1;
        int i = 0;
        for (; i < ret; i++) {
            Book book=bookshelf.getBook(i);
            if(book.getBookName().equals(delName)){
                pos=i;
                break;
            }
    }
        if(i==ret){
            System.out.println("没有你要删除的书");
            return;
        }
        for (int j = pos; j <ret-1; j++) {
            Book book=bookshelf.getBook(j+1);
            bookshelf.setBook(j,book);
        }
        bookshelf.setUseSize(ret-1);
        System.out.println("删除成功");
    }
}
